#include <iostream>
#include <string.h>

const int MAX = 1000000000;
const int MAXS = 10010;
const int MAXT = 1010;

char t[MAXT], s[MAXS];
int sum_s[MAXS]; // sum(i -> j) = sum_s[j + 1] - sum_s[i]
//int next[MAXS][26];
//int current[26];
int slen, tlen;
int istar;

int sum_t(int a, int b)
{
	int sum = 0;
	for (int i = a; i < b; ++i)
		sum += (t[i] - 'a' + 1);
	return sum;
}

int solve()
{
	if (istar < 0) {
		char* f = strstr(s, t);
		return (f != NULL) ? sum_t(0, tlen) : MAX;
	} else if (istar == 0) {
		char* f = strstr(s, t + 1);
		return (f != NULL) ? sum_t(1, tlen) : MAX;
	} else if (istar == tlen - 1) {
		t[tlen - 1] = 0;
		char* f = strstr(s, t);
		int ans = (f != NULL) ? sum_t(0, tlen - 1) : MAX;
		t[tlen - 1] = '*';
		return ans;
	} else {
		int t1len = istar, t2len = tlen - istar - 1;
		char* t1 = new char[t1len];
		strncpy(t1, t, t1len);
		t1[t1len] = 0;
		char* t2 = new char[t2len];
		strncpy(t2, t + istar + 1, t2len);
		t2[t2len] = 0;
		//puts(t1);
		//puts(t2);

		int i1 = 0, i2 = 0;
		int ans = MAX;
		while (i1 < slen)
		{
			char* f1 = strstr(s + i1, t1);
			if (f1 == NULL) break;
			i1 = f1 - s;
			char* f2 = strstr(s + std::max(i1 + t1len, i2), t2);
			if (f2 == NULL) break;
			i2 = f2 - s;
			ans = std::min(ans, sum_s[i2 + t2len] - sum_s[i1]);
			//printf("%d %d %d\n", i1, i2, sum_s[i2 + t2len] - sum_s[i1]);
			i1 += 1;
		}
		return ans;
	}
}

int main()
{
	scanf("%s%s", t, s);
	slen = strlen(s);
	tlen = strlen(t);
	//for (int i = 0; i < 26; ++i) current[i] = 0;
	sum_s[0] = 0;
	for (int i = 1; i < slen; ++i)
	{
		//for (int j = 0; j < 26; ++j) next[i][j] = slen;
		//int c = s[i] - 'a';
		//for (int j = 0; j < 26; ++j) next[current[j]][c] = i;
		//current[c] = i;
		sum_s[i] = sum_s[i - 1] + (s[i - 1] - 'a' + 1);
	}
	sum_s[slen] = sum_s[slen - 1] + (s[slen - 1] - 'a' + 1);

	char* mark = strchr(t, '?');
	char* star = strchr(t, '*');
	istar = (star != NULL) ? star - t : -1;
	int ans = MAX;
	if (mark != NULL) {
		for (int i = 0; i < 26; ++i) {
			t[mark - t] = (char) ('a' + i);
			ans = std::min(ans, solve());
		}		
	} else {
		ans = solve();
	}

	printf("%d\n", ans == MAX ? -1 : ans);

#ifndef ONLINE_JUDGE
	system("pause");
#endif
	return 0;
}